<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends Auth_Controller {

    public function index(){
        //判断用户权限
        //1 超级管理员
        //统计客户所有客户
        $this->load->model('customer_mdl');

        //统计当前账号下客户
        $data['z_cust'] = $this->customer_mdl->count_cust();

        //今日新增
        $date = date('Y-m-d',$_SERVER['REQUEST_TIME']);
        $date = strtotime($date);
        $this->db->where('create_time >',$date);
        $data['x_cust'] = $this->customer_mdl->count_cust();

        //统计公海客户
        $data['z_common'] = $this->customer_mdl->count_common();

        //今日新增
        $this->db->where('create_time >',$date);
        $data['x_common'] = $this->customer_mdl->count_common();

        //统计未打电话未打的客户
        $this->db->where('ctype',1);
        $data['kf_cust'] = $this->customer_mdl->count_cust();

        //统计等待上门
        $this->db->where('ctype',4);
        $data['yx_cust'] = $this->customer_mdl->count_cust();

        if($_SESSION['user']['group'] != 1){
            $this->_view('index',$data);
        }else{
            $this->set_view($data);
        }

    }

    public function set_view($data){
        //获取所有员工数据
        $this->load->model('users_mdl');

        $date = date('Y-m-d',$_SERVER['REQUEST_TIME']);
        $date = strtotime($date);

        $this->db->where('group',2);
        $this->db->select('id,name');
        $list = $this->users_mdl->select();

        //统计当前用户所有客户
        foreach($list as $k => $v){
            //查询员工总客户
            $this->db->where('user_id',$v['id']);
            $list[$k]['zs'] = $this->customer_mdl->get_count();
            //查询今日新增客户
            $this->db->where('user_id',$v['id']);
            $this->db->where('create_time >=',$date);
            $list[$k]['xz'] = $this->customer_mdl->get_count();

            //查询电话未打
            $this->db->where('user_id',$v['id']);
            $this->db->where('ctype',1);
            $list[$k]['wd'] = $this->customer_mdl->get_count();

            //查询电话未打
            $this->db->where('user_id',$v['id']);
            $this->db->where('ctype',4);
            $list[$k]['sm'] = $this->customer_mdl->get_count();
        }

        $data['list'] = $list;
        $this->_view('admin',$data);

    }

}

/* End of file Home.php */
/* Location: ./application/controllers/Home.php */